/**
 * 获取指定class的父节点
 * @param {HTMLElement} element 
 * @param {String} className 
 */
function getParents(element, className) {
  //dom.getAttribute('class')==dom.className，两者等价
  var returnParentElement = null;
  function getpNode(element, className) {
    //创建父级节点的类数组
    let pClassList = element.parentNode.getAttribute('class');
    let pNode = element.parentNode;
    if (!pClassList) {
      //如果未找到类名数组，就是父类无类名，则再次递归
      getpNode(pNode, className);
    } else if (pClassList && pClassList.indexOf(className) < 0) {
      //如果父类的类名中没有预期类名，则再次递归
      getpNode(pNode, className);
    } else if (pClassList && pClassList.indexOf(className) > -1) {
      returnParentElement = pNode;
    }
  }
  getpNode(element, className);
  //console.log(returnParentElement);
  return returnParentElement;
}

export { getParents };